package com.edgarli.web.controller.movies;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edgarli.common.annotation.Log;
import com.edgarli.common.core.controller.BaseController;
import com.edgarli.common.core.domain.AjaxResult;
import com.edgarli.common.enums.BusinessType;
import com.edgarli.movies.domain.TMoviesConfig;
import com.edgarli.movies.service.ITMoviesConfigService;
import com.edgarli.common.utils.poi.ExcelUtil;
import com.edgarli.common.core.page.TableDataInfo;

/**
 * 影音配置Controller
 *
 * @author ruoyi
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/movies/config")
public class TMoviesConfigController extends BaseController {
    @Autowired
    private ITMoviesConfigService tMoviesConfigService;

    /**
     * 查询影音配置列表
     */
    @PreAuthorize("@ss.hasPermi('movies:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMoviesConfig tMoviesConfig) {
        startPage();
        List<TMoviesConfig> list = tMoviesConfigService.selectTMoviesConfigList(tMoviesConfig);
        return getDataTable(list);
    }

    /**
     * 导出影音配置列表
     */
    @PreAuthorize("@ss.hasPermi('movies:config:export')")
    @Log(title = "影音配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMoviesConfig tMoviesConfig) {
        List<TMoviesConfig> list = tMoviesConfigService.selectTMoviesConfigList(tMoviesConfig);
        ExcelUtil<TMoviesConfig> util = new ExcelUtil<TMoviesConfig>(TMoviesConfig.class);
        util.exportExcel(response, list, "影音配置数据");
    }

    /**
     * 获取影音配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('movies:config:query')")
    @GetMapping(value = "/{moviesConfigId}")
    public AjaxResult getInfo(@PathVariable("moviesConfigId") Long moviesConfigId) {
        return AjaxResult.success(tMoviesConfigService.selectTMoviesConfigByMoviesConfigId(moviesConfigId));
    }

    /**
     * 新增影音配置
     */
    @PreAuthorize("@ss.hasPermi('movies:config:add')")
    @Log(title = "影音配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMoviesConfig tMoviesConfig) {
        if (tMoviesConfig.getMrbjFg() == 1) {
           tMoviesConfigService.updateOthreMrbjFg(tMoviesConfig, 0);
        }
        return toAjax(tMoviesConfigService.saveOrUpdate(tMoviesConfig));
    }

    /**
     * 修改影音配置
     */
    @PreAuthorize("@ss.hasPermi('movies:config:edit')")
    @Log(title = "影音配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMoviesConfig tMoviesConfig) {
         if (tMoviesConfig.getMrbjFg() == 1) {
            tMoviesConfigService.updateOthreMrbjFg(tMoviesConfig, 0);
        }
        return toAjax(tMoviesConfigService.saveOrUpdate(tMoviesConfig));
    }

    /**
     * 删除影音配置
     */
    @PreAuthorize("@ss.hasPermi('movies:config:remove')")
    @Log(title = "影音配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{moviesConfigIds}")
    public AjaxResult remove(@PathVariable Long[] moviesConfigIds) {
        return toAjax(tMoviesConfigService.deleteTMoviesConfigByMoviesConfigIds(moviesConfigIds));
    }
}
